import { z } from 'zod';
import { MessageType, FileType } from '../constants/messageType';

/**
 * Zod 校验器：用于 controller 中验证请求体
 */
export const SendMessageDTO = z.object({
  conversation_id: z.number(),
  type: z.nativeEnum(MessageType),
  content: z.string(),
  sender_id: z.number(),
  receiver_id: z.number().optional(),
  group_id: z.number().optional(),
  has_attachment: z.literal(1).optional(),
  attachment: z
    .object({
      url: z.string().url(),
      name: z.string().optional(),
      size: z.number().optional(),
      mime: z.string().optional(),
      type: z.nativeEnum(FileType)
    })
    .optional()
});

/**
 * 推导出的输入类型：用于 service 函数入参
 */
export type MessageSendInput = z.infer<typeof SendMessageDTO>;
